home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / os2tools / bnklysrc / b_search.c < prev    next >
C/C++ Source or Header  |  1989-02-13  |  14KB  |  371 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software <no-Inc>                   */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          No-Cost<no-tm> Software.                       */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello  */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*               This module was written by Vince Perriello                 */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                   BinkleyTerm Phone list Search Module                   */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.210.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU SHOULD  IMMEDIATELY CONTACT THE AUTHORS    */
  27. /*    AT THE  ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO    */
  28. /*    USE   THIS  FILE  WITHOUT  HAVING   ACCEPTED  THE  TERMS  OF   THE    */
  29. /*    BINKLEYTERM  LICENSING AGREEMENT,  OR SUCH OTHER  AGREEMENT AS YOU    */
  30. /*    ARE ABLE TO REACH WITH THE AUTHORS.                                   */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /*    The Authors can be reached at the following addresses:                */
  34. /*                                                                          */
  35. /*    Robert C. Hartman                      Vincent E. Perriello           */
  36. /*    Spark Software                         VEP Software                   */
  37. /*    427-3 Amherst Street                   111 Carroll Street             */
  38. /*    CS2032, Suite 232                      Naugatuck, CT 06770            */
  39. /*    Nashua, NH 03061                                                      */
  40. /*                                                                          */
  41. /*    FidoNet 1:132/101                      FidoNet 1:141/491              */
  42. /*    Data    (603) 888-8179                 Data    (203) 729-7569         */
  43. /*                                                                          */
  44. /*    Please feel free to contact us at any time to share your comments     */
  45. /*    about our software and/or licensing policies.                         */
  46. /*                                                                          */
  47. /*--------------------------------------------------------------------------*/
  48.  
  49.  
  50. #include <stdio.h>
  51. #include <signal.h>
  52. #include <ctype.h>
  53. #include <conio.h>
  54. #include <string.h>
  55. #include <stdlib.h>
  56.  
  57. #ifdef __TURBOC__
  58. #include <alloc.h>
  59. #else
  60. #include <malloc.h>
  61. #endif
  62.  
  63. #include "com.h"
  64. #include "xfer.h"
  65. #include "zmodem.h"
  66. #include "keybd.h"
  67. #include "sbuf.h"
  68. #include "sched.h"
  69. #include "externs.h"
  70. #include "prototyp.h"
  71.  
  72. static int SaveScanList (int);
  73. static void wait_for_keypress(void);
  74.  
  75. int list_search ()
  76. {
  77.    int saved_baud;
  78.    long t1, timerset ();
  79.    int i, k, l;
  80.    int dirty;
  81.    int zone, net, node, point;
  82.    unsigned int kbd_input;
  83.  
  84.    static unsigned int save_chars[] = {
  85.       SHF1, SHF2, SHF3, SHF4, SHF5,
  86.       SHF6, SHF7, SHF8, SHF9, SHF10
  87.    };
  88.  
  89.    static unsigned int load_chars[] =  {
  90.       ALTF1, ALTF2, ALTF3, ALTF4, ALTF5,
  91.       ALTF6, ALTF7, ALTF8, ALTF9, ALTF10
  92.    };
  93.  
  94.    static unsigned int command_chars[] = {
  95.       PF1, PF2, PF3, PF4, PF5,
  96.       PF6, PF7, PF8, PF9, PF10
  97.    };
  98.  
  99.    /*
  100.     * *     Input the phone numbers we want to scan *
  101.     *
  102.     */
  103.  
  104.    dirty = 1;
  105.    for (;;)
  106.       {
  107.       if (dirty)
  108.          {
  109.          cprintf ("\033[H\033[J\r\n");
  110.          cprintf ("F1 ... F10 = input phone number, (ENTER) = start, (ESC) = abort\r\n");
  111.          cprintf ("ALT-Fn = load saved set (n), Shift-Fn = save into set (n)\r\n");
  112.          cprintf ("Phone Numbers currently Selected:\r\n\r\n");
  113.          for (k = 0; k < 10; k += 2)
  114.             {
  115.             cprintf ("%2d: %35s %2d: %35s\r\n",
  116.                      k + 1, scan_list[k], k + 2, scan_list[k + 1]);
  117.             }
  118.          cprintf ("\r\nInput Command: ");
  119.          dirty = 0;
  120.          }
  121.  
  122.       while (!KEYPRESS ())
  123.          time_release ();
  124.       kbd_input = FOSSIL_CHAR ();
  125.  
  126.       if (((kbd_input & 0xff) == '\n') || ((kbd_input & 0xff) == '\r'))
  127.          break;
  128.  
  129.       if ((kbd_input & 0xff) == ESC)
  130.          return (0);
  131.  
  132.       for (k = 0; k < 10; k++)
  133.          {
  134.          if (kbd_input == save_chars[k])         /* Save into a set?   */
  135.             {
  136.             SaveScanList(k);                     /* Yes, do it         */
  137.             dirty = 1;                           /* Force redisplay    */
  138.             k = 10;                              /* Then fool the logic*/
  139.             break;
  140.             }
  141.  
  142.          if (kbd_input == load_chars[k])         /* Load from a set?   */
  143.             {
  144.             LoadScanList(k,1);                   /* Yes, do it         */
  145.             dirty = 1;                           /* Force redisplay    */
  146.             k = 10;                              /* Then fool the logic*/
  147.             break;
  148.             }
  149.  
  150.          if (kbd_input == command_chars[k])      /* Plain old Fkey?    */
  151.             break;                               /* Yup, get out now   */
  152.          }
  153.  
  154.       if (k == 10)                               /* Not a function key */
  155.          {
  156.          k = (kbd_input & 0xff) - '0';           /* Convert from digit */
  157.          if ((k < 0) || (k > 9))                 /* Was it a digit?    */
  158.             continue;                            /* No, throw char out */
  159.          if (!k)                                 /* Is it a zero?      */
  160.             k = 9;                               /* That's 9 to us     */
  161.          else --k;                               /* Else make zero-rel */
  162.          }
  163.  
  164.       cprintf ("Element Chosen = %2d\r\n", k + 1);
  165.       if (scan_list[k] != NULL)
  166.          {
  167.          cprintf ("Currently contains %s\r\n", scan_list[k]);
  168.          cprintf ("(ENTER) = save, (space)(ENTER) = delete, or enter new number:\r\n");
  169.          }
  170.       else
  171.          {
  172.          cprintf ("(ENTER) or (space)(ENTER) = cancel, or enter new number:\r\n");
  173.          }
  174.       gets (junk);                               /* Get the user's input */
  175.       ++dirty;                                   /* Always redisplay     */
  176.       if ((l = strlen (junk)) == 0)              /* If nothing there,    */
  177.          continue;                               /* move along           */
  178.  
  179.       if (l == 1 && *junk == ' ')                /* If just a space...   */
  180.          {
  181.          if (scan_list[k] != NULL)               /* Delete old number    */
  182.             free (scan_list[k]);
  183.          scan_list[k] = NULL;                    /* Clean up the ref     */
  184.          /*      ++dirty;  *//* Force a redisplay    */
  185.          continue;                               /* End this iteration   */
  186.          }
  187.  
  188.       if (scan_list[k] != NULL)                  /* Get rid of old num   */
  189.          free (scan_list[k]);
  190.       if ((scan_list[k] = malloc (++l)) == NULL) /* Allocate space       */
  191.          {
  192.          cprintf ("\r\nUnable to allocate space for number!\r\n");
  193.          return (0);                             /* Get out for error    */
  194.          }
  195.       strcpy (scan_list[k], junk);               /* Save new number      */
  196.       /*   ++dirty;     *//* Force a redisplay    */
  197.       }
  198.  
  199.    /*
  200.     * *     Actual Search logic *
  201.     *
  202.     */
  203.    status_line ("#Starting Phone List Scan");
  204.    for (;;)
  205.       {
  206.       l = 0;
  207.       for (k = 0; k < 10; k++)
  208.          {
  209.          if (scan_list[k] == NULL)
  210.             continue;
  211.          strcpy (junk, scan_list[k]);
  212.          if (!isdigit (junk[0]) && junk[0] != '\"')
  213.             {
  214.             fidouser (junk, &zone, &net, &node, &point);
  215.             if ((net != -1) && (node != -1) && (zone != -1))
  216.                {
  217.                if (zone == alias[0].Zone)
  218.                   sprintf (junk, "%d/%d", net, node);
  219.                else sprintf (junk, "%d:%d/%d", zone, net, node);
  220.                }
  221.             else continue;
  222.             }
  223.          if (strchr (junk, '/') != NULL)
  224.             {
  225.             if (!nodeproc (junk))
  226.                break;
  227.             strcpy (junk, newnodedes.PhoneNumber);
  228.             }
  229.          caller = 0;
  230.          saved_baud = baud;
  231.          if (try_1_connect (junk))               /* Attempt to connect     */
  232.             {
  233.             status_line ("#Connected to list element %d", k + 1);
  234.             free (scan_list[k]);
  235.             scan_list[k] = NULL;
  236.             gong ();
  237.             return (1);
  238.             }
  239.          ++l;
  240.          baud = saved_baud;
  241.          MDM_ENABLE (btypes[baud].rate);
  242.          cur_baud = atoi (btypes[baud].str);
  243.          t1 = timerset (200);
  244.          while (!timeup (t1))                    /* pause for 2 seconds */
  245.             {
  246.             if (KEYPRESS ())
  247.                {
  248.                i = FOSSIL_CHAR () & 0xff;
  249.                if (i == ESC)                     /* Abort for ESCape    */
  250.                   {
  251.                   status_line ("!Connection attempt aborted");
  252.                   return (0);
  253.                   }
  254.                }
  255.             time_release ();
  256.             }
  257.          }
  258.       if (!l)
  259.          return (0);
  260.       }
  261. }
  262.  
  263. LoadScanList(number,report_errors)
  264. int number;                                     /* Set number to load */
  265. int report_errors;                              /* Whether to report  */
  266. {
  267.     int k, l;
  268.     FILE *ScanFile;
  269.     sprintf(junk,"%sBinkScan.LS%c",BINKpath, number + '0');
  270.     if ((ScanFile = fopen(junk, "rb")) == NULL)
  271.         {
  272.         if (report_errors)
  273.             {
  274.             cprintf("Could not open %s\r\n",junk);
  275.             wait_for_keypress();
  276.             }
  277.         return(0);
  278.         }
  279.     for (k = 0; k < 10; k++)
  280.         {
  281.         if (fread(junk, 36, 1, ScanFile) != 1)
  282.             {
  283.             if (report_errors)
  284.                 {
  285.                 cprintf("Error reading data from set %d\r\n", number + 1);
  286.                 wait_for_keypress();
  287.                 }
  288.             fclose(ScanFile);
  289.             return(0);
  290.             }
  291.  
  292.         if (scan_list[k] != NULL)
  293.             {
  294.             free(scan_list[k]);
  295.             scan_list[k] = NULL;
  296.             }
  297.  
  298.         if (l = strlen(junk))
  299.             {
  300.             if ((scan_list[k] = malloc (++l)) == NULL) /* Allocate space    */
  301.                 {
  302.                 if (report_errors)
  303.                     {
  304.                     cprintf("Unable to allocate space for set %d\r\n", number + 1);
  305.                     wait_for_keypress();
  306.                     }
  307.                 fclose(ScanFile);
  308.                 return(0);
  309.                 }
  310.  
  311.             strcpy (scan_list[k], junk);               /* Save new number   */
  312.             }
  313.         }
  314.     l = fclose (ScanFile);
  315.     if (report_errors)
  316.         {
  317.         if (l)
  318.             cprintf("Error closing file for set %d\r\n", number + 1);
  319.         else
  320.             cprintf("Set %d successfully loaded.\r\n", number + 1);
  321.         wait_for_keypress();
  322.         }
  323.     return(l);
  324. }
  325.  
  326. static SaveScanList(number)
  327. int number;                                     /* Set number to save */
  328. {
  329.     int k, l;
  330.     FILE *ScanFile;
  331.     sprintf(junk,"%sBinkScan.LS%c",BINKpath, number + '0');
  332.     if ((ScanFile = fopen(junk, "wb")) == NULL)
  333.         {
  334.         cprintf("Could not open %s\r\n",junk);
  335.         wait_for_keypress();
  336.         return(0);
  337.         }
  338.     for (k = 0; k < 10; k++)
  339.         {
  340.         for (l = 0; l < 36; l++)
  341.             junk[l] = '\0';
  342.  
  343.         if (scan_list[k] != NULL)
  344.             strcpy(junk,scan_list[k]);
  345.  
  346.         if (fwrite(junk, 36, 1, ScanFile) != 1)
  347.             {
  348.             cprintf("Error writing data to set %d\r\n", number + 1);
  349.             wait_for_keypress();
  350.             fclose(ScanFile);
  351.             return(0);
  352.             }
  353.         }
  354.  
  355.     if (l = fclose(ScanFile))
  356.         cprintf("Error closing file for set %d\r\n", number + 1);
  357.     else
  358.         cprintf("Current list of numbers saved to set %d\r\n", number + 1);
  359.  
  360.     wait_for_keypress();
  361.     return(l);
  362. }
  363.  
  364. static void wait_for_keypress(void)
  365. {
  366.     cprintf("Press any key to continue.\r\n");
  367.     while (!KEYPRESS ())
  368.         time_release ();
  369.     FOSSIL_CHAR ();
  370. }
  371.